package com.wzh.service.serviceImpl;

import com.wzh.pojo.Contact;
import com.wzh.dao.ContactDao;
import com.wzh.dao.daoImpl.ContactDaoImpl;
import com.wzh.service.ContactService;
import com.wzh.utils.DealUtil;

public class ContactServiceImpl implements ContactService {

	ContactDao contactDao = new ContactDaoImpl();

	@Override
	public boolean addContact(Contact contact) {
		String name = contact.getName();
		String phoneNum = contact.getTelephone();
		if(name.equals("")&&phoneNum.equals("")){
			return false;
		}
		int status = contactDao.add(contact);
		if(status==0){
			return false;
		}else{
			return true;
		}
	}

	@Override
	public int deleteById(int id) {
		int status = contactDao.delete(id);
		return status;
	}

	@Override
	public String[][] queryAllContact() {
		return DealUtil.spiltNum(contactDao.queryAllContacts());
	}

	@Override
	public int updateContact(int id, String name, String telephone, String address) {
		int status = 0;
		Contact newAddressBook = new Contact(name, telephone, address);
		contactDao.updateContact(id, newAddressBook);
		return status;
	}

}
